package com.ctshk.sapp.order.hotel.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.hotel.req.HotelManualOrderReq;
import com.ctshk.rpc.hotel.service.IHotelManualOrderService;
import com.ctshk.rpc.hotel.service.IHotelOrderReceiptService;
import com.ctshk.rpc.order.hotel.dto.HotelOrderReceiptGetDTO;
import com.ctshk.rpc.order.hotel.dto.HotelOrderSubmitDTO;
import com.ctshk.rpc.order.hotel.req.HotelOrderCollectionReq;
import com.ctshk.rpc.order.hotel.req.HotelOrderReceiptSaveReq;
import com.ctshk.rpc.order.hotel.req.HotelOrderSubmitReq;
import com.ctshk.rpc.order.hotel.service.IHotelOrderBookingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @description 酒店订单-预订中心
 * @author 谢诗宏
 * @date 2021/4/22
 */
@Api(value = "酒店订单",tags = "预订中心")
@RestController
@RequestMapping("/booking")
public class HotelOrderBookingController extends BaseController {

    @DubboReference
    private IHotelOrderBookingService hotelOrderBookingService;
    @DubboReference
    private IHotelManualOrderService hotelManualOrderService;
    @DubboReference
    private IHotelOrderReceiptService hotelOrderReceiptService;

    @ApiOperation(value = "提交订单", notes = "提交订单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "提交订单", operDesc = "酒店产品-订单中心-提交订单")
    @PostMapping("/submit")
    public Result<HotelOrderSubmitDTO> submit(@RequestBody @Valid HotelOrderSubmitReq req) {
        return Result.success(hotelOrderBookingService.submit(req, getCurrentUser(getRequest())));
    }

    @ApiOperation(value = "提交外挂单", notes = "提交外挂单")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "提交订单", operDesc = "酒店产品-订单中心-提交订单")
    @PostMapping("/manual")
    public Result<Long> manual(@RequestBody @Valid HotelManualOrderReq req) {
        return Result.success(hotelManualOrderService.addHotelManualOrder(req, getCurrentUser(getRequest()).getId()));
    }

    @ApiOperation(value = "支付", notes = "支付完成")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "支付", operDesc = "酒店产品-订单中心-支付完成")
    @PostMapping("/pay")
    public Result<Long> payment(@RequestBody @Valid List<HotelOrderCollectionReq> reqs) {
        return hotelOrderBookingService.payment(reqs, getCurrentUser(getRequest()).getId());
    }

    @ApiOperation(value = "更新收据", notes = "更新收据(下载，打印时候调用)")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "更新收据", operDesc = "酒店-订单中心-更新收据")
    @PostMapping("/receipt/update")
    public Result saveReceipt(@RequestBody HotelOrderReceiptSaveReq req) {
        Long userId = getCurrentUser(getRequest()).getId();
        int num = hotelOrderReceiptService.update(req, userId);
        return Result.success(num);
    }

    @ApiOperation(value = "查询收据", notes = "查询收据")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "查询收据", operDesc = "酒店-订单中心-查询收据")
    @GetMapping("/receipt/{orderId}")
    public Result<HotelOrderReceiptGetDTO> getReceiptByOrderId(@PathVariable("orderId") Long orderId) {
        HotelOrderReceiptGetDTO result = hotelOrderReceiptService.getReceiptByOrderId(orderId);
        return Result.success(result);
    }

}
